<?php
namespace App\Hospital\Models;

use App\Models\HospitalAppoint;
use Dcat\Admin\Admin;
use Illuminate\Database\Eloquent\Builder;

class HospitalAppointModel extends HospitalAppoint{


    protected static function boot()
    {
        parent::boot();

        static::addGlobalScope('hospital_id', function (Builder $builder) {
            $builder->where('hospital_id', Admin::user()->hospital_id);
        });
    }

    public static function booted()
    {
        parent::booted();
        static::creating(function (HospitalAppoint $model){
            if(empty($model->hospital_id)){
                $model->hospital_id = Admin::user()->hospital_id;
            }
            if(empty($model->is_delete)){
                $model->is_delete = 0;
            }

            if(empty($model->cycle)){
                $model->cycle = 0;
            }
            if(empty($model->sure_date)){
                $model->sure_date = '';
            }
            if(empty($model->non_date)){
                $model->non_date = '';
            }
            if(empty($model->weeks)){
                $model->weeks = '';
            }
        });
    }
}
